﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace desktop
{
    public static class PublicWay
    {
        /// <summary>
        /// 对DragIn保存的程序图标类型判断（公用图标或是独有图标）
        /// </summary>
        /// <param name="fullName">文件名或路径</param>
        /// <returns>lnk\exe 为独有图标，即 Models.MarkType.AppName</returns>
        public static Models.MarkType IconType(string fullName)
        {
            string a = fullName.GetExtensionName().ToLower();
            a = fullName.GetExtensionName().ToLower();
            Models.MarkType r;
            if (fullName.GetExtensionName().ToLower() == "lnk" || fullName.GetExtensionName().ToLower() == "exe")
            {
                r = Models.MarkType.AppName;
            }
            else if (IsImage(fullName))
            {
                r = Models.MarkType.Image;
            }
            else
            {
                r = Models.MarkType.ExtensionName;
            }
            return r;
        }


        /// <summary>
        /// 判断文件是否为图片
        /// </summary>
        /// <param name="path">文件的完整路径</param>
        /// <returns>返回结果</returns>
        private static bool IsImage(string path)
        {
            try
            {
                string e = path.GetExtensionName().ToLower();
                if (!File.Exists(path))
                    return false;
                if (e != "jpg" && e != "jpeg" && e != "gif" && e != "png")
                {
                    return false;
                }
                Console.WriteLine(path);
                System.Drawing.Image img = System.Drawing.Image.FromFile(path);
                return true;
            }
            catch
            {
                return false;
            }
        }



    }
}
